/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.pages.role;

import java.util.Arrays;
import java.util.List;

import com.eelpo.cmmp.core.wicket.panel.container.SearchPanel;
import com.eelpo.cmmp.uac.dao.vo.Role;
import com.eelpo.cmmp.uac.dao.vo.enumed.Status;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

/**
 * <pre>
 * 角色管理查询参数面板
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class RoleSearchPanel extends SearchPanel {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4897791468268434575L;

	public RoleSearchPanel(String id, Role role) {
		super(id);

		add(renderFeedbackPanel("feedback"));

		renderRoleNameTextField(role);
		renderDescriptionTextField(role);
		renderRoleStatusDropDownChoice(role);
		renderAddButton();
	}

	public void renderRoleNameTextField(Role role) {
		add(new TextField<String>("txtName", new PropertyModel<String>(role, "name")));
	}

	public void renderDescriptionTextField(Role role) {
		add(new TextField<String>("txtDescription", new PropertyModel<String>(role, "description")));
	}

	public void renderRoleStatusDropDownChoice(Role role) {
		List<Status> dataList = Arrays.asList(new Status[] { Status.ENABLED, Status.DISABLED, Status.ALL });
		IModel<Status> model = new PropertyModel<Status>(role, "status");
		IChoiceRenderer<Status> choiceRenderer = new ChoiceRenderer<Status>("label", "value");
		add(new DropDownChoice<Status>("selStatus", model, dataList, choiceRenderer));
	}

	private void renderAddButton() {
		Link<Void> lnkAdd = new Link<Void>("btnAdd") {
			private static final long serialVersionUID = -940868358118439402L;

			public void onClick() {
				setResponsePage(new AddOrEditRole());
			}
		};
		add(lnkAdd);
	}

}
